package com.example.seckill.mappstruct;

import com.example.seckill.controller.vo.PromoVO;
import com.example.seckill.domain.PromoDO;
import com.example.seckill.service.model.PromoModel;
import org.mapstruct.Context;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.TimeZone;

@Mapper
public interface PromoMap {
    PromoMap INSTANCE = Mappers.getMapper(PromoMap.class);

    @Mapping(target = "startDate",expression = "java(cn.hutool.core.date.LocalDateTimeUtil.of(promoDO.getStartDate()))")
    @Mapping(target = "endDate",expression = "java(cn.hutool.core.date.LocalDateTimeUtil.of(promoDO.getEndDate()))")
    PromoModel convertFromDO(PromoDO promoDO);

    @Mapping(target = "startDate",expression = "java(promoModel.getStartDate().toInstant(java.time.ZoneOffset.ofHours(8)).toEpochMilli())")
    @Mapping(target = "endDate",expression = "java(promoModel.getEndDate().toInstant(java.time.ZoneOffset.ofHours(8)).toEpochMilli())")
    PromoVO convertFromModel(PromoModel promoModel);
}
